package qc.module.platform.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.module.platform.dto.apiFilter.ApiFilterDto;
import qc.module.platform.dto.apiFilter.ApiFilterQueryConditionDto;
import qc.module.platform.service.ApiFilterService;

import java.util.List;

/**
 * ApiFilterController
 * 接口日志过滤规则Controller
 *
 * @author QuCheng Tech
 * @create 2023/11/03
 */
@RestController
@RequestMapping("/apifilter")
public class ApiFilterController {
    private ApiFilterService apiFilterService;

    @Autowired
    public void setApiFilterService(ApiFilterService apiFilterService) {
        this.apiFilterService = apiFilterService;
    }

    /**
     * 查询接口日志过滤规则记录
     *
     * @param conditionDto 查询条件dto
     * @return 接口日志过滤规则记录集合
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/query", method = {RequestMethod.GET, RequestMethod.POST})
    public List<ApiFilterDto> query(@RequestBody ApiFilterQueryConditionDto conditionDto) {
        return apiFilterService.query(conditionDto);
    }

    /**
     * 获取指定接口日志过滤规则记录
     *
     * @param id 规则ID
     * @return 指定接口日志过滤规则记录
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/get", method = {RequestMethod.GET})
    public ApiFilterDto getApiFilterByParam(@RequestParam String id) {
        return apiFilterService.get(id);
    }

    /**
     * 获取指定接口日志过滤规则记录
     *
     * @param id 规则ID
     * @return 指定接口日志过滤规则记录
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/get/{id}", method = {RequestMethod.GET})
    public ApiFilterDto getApiFilterByPath(@PathVariable String id) {
        return apiFilterService.get(id);
    }

    /**
     * 新增接口日志过滤规则记录
     *
     * @param dto 新增内容dto
     * @return 返回null表示成功，其他表示错误或提示信息
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public String add(@RequestBody ApiFilterDto dto) {
        return apiFilterService.add(dto);
    }

    /**
     * 修改接口日志过滤规则记录
     *
     * @param dto 修改内容dto
     * @return 返回null表示成功，其他表示错误或提示信息
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST})
    public String update(@RequestBody ApiFilterDto dto) {
        return apiFilterService.update(dto);
    }

    /**
     * 删除指定接口日志过滤规则记录
     * 物理删除
     *
     * @param id 规则ID
     * @return 返回null表示成功，其他表示错误或提示信息
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/delete", method = {RequestMethod.DELETE})
    public String deleteByParam(@RequestParam String id) {
        return apiFilterService.delete(id);
    }

    /**
     * 删除指定接口日志过滤规则记录
     * 物理删除
     *
     * @param id 规则ID
     * @return 返回null表示成功，其他表示错误或提示信息
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/delete/{id}", method = {RequestMethod.DELETE})
    public String deleteByPath(@PathVariable String id) {
        return apiFilterService.delete(id);
    }

    /**
     * 启用接口日志过滤规则记录
     *
     * @param id 规则ID
     * @return 返回null表示成功，其他表示错误或提示信息
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/enable", method = {RequestMethod.POST, RequestMethod.PUT})
    public String enableByParam(@RequestParam String id) {
        return apiFilterService.enable(id);
    }

    /**
     * 启用接口日志过滤规则记录
     *
     * @param id 规则ID
     * @return 返回null表示成功，其他表示错误或提示信息
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/enable/{id}", method = {RequestMethod.POST, RequestMethod.PUT})
    public String enableByPath(@PathVariable String id) {
        return apiFilterService.enable(id);
    }

    /**
     * 禁用接口日志过滤规则记录
     *
     * @param id 规则ID
     * @return 返回null表示成功，其他表示错误或提示信息
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/disable", method = {RequestMethod.POST, RequestMethod.PUT})
    public String disableByParam(@RequestParam String id) {
        return apiFilterService.disable(id);
    }

    /**
     * 禁用接口日志过滤规则记录
     *
     * @param id 规则ID
     * @return 返回null表示成功，其他表示错误或提示信息
     * @author QcCheng Tech
     * @since 2023/11/03
     */
    @RequestMapping(value = "/disable/{id}", method = {RequestMethod.POST, RequestMethod.PUT})
    public String disableByPath(@PathVariable String id) {
        return apiFilterService.disable(id);
    }

}
